
/**
 * 分包出勤
 */
var myEcharts1;
$(function(){
	
	myEcharts1 = echarts.init(document.getElementById('echarts_1'));
	
	
	
	loadPageData();
	
	$(window).resize(function(){
		myEcharts1.resize();
	});


	
	
})





/**
 * -----------------------------------------------------------------------------------------------------------------------------------
 * 【分包】加载数据-接口
 */
function loadPageData(){
	clearInterval(tempInterPage);
	if(tempPageState){
		tempPageState = false;
	}
	$.post(ctxPath+'data/face/selectContractor', {}, function(result) {
		if(result.success){
			var data = result.data;
			$("#page_list").empty();
			for(var i=0; i<data.length; i++){
				var obj = data[i];
				obj.title = obj.name;
				obj.value = obj.timeCount;
				var s = '<div class="page_box">';
				if((i+1)%2 == 0){
					s = '<div class="page_box" style="background-color: rgba(128, 191, 255, 0.08);">';
				}
				s += '	<span class="page_text_1">'+(i+1)+'.'+obj.title+'</span>';
				s += '	<span class="page_text_2">'+obj.attendCount+'/'+obj.sum+'</span>';
				s += '	<span class="page_text_3">'+obj.timeCount+'</span>';
				s += '</div>';
				$("#page_list").append(s);
			}
			setTimeout(function () {
				showEchartsPage(data);
				myEcharts1.resize();
			}, 2000)
			if(data.length > 5){
				clearInterval(tempInterPage);
				tempInterPage = setInterval(function(){
					if(!tempPageState){
						infoPage();
					}
				}, 4000);
			}
		}
	})
}

var tempInterPage, tempPageState;
/**
 * ------------------------------------------------------------------------------------------------------------------------------------
 * 滚动
 * @returns
 */
function infoPage(){
	tempPageState = true;
	var li = $("#page_list>.page_box:eq(0)").clone();
	$("#page_list>.page_box:eq(0)").animate({marginTop:"-1.38rem"}, 2000, function(){
		$("#page_list>.page_box:eq(0)").remove();
		if(tempPageState){
			$("#page_list").append(li);
		}
		tempPageState = false;
	})
}



var colorList = ['#8d7fec', '#5085f2', '#4168FF', '#47CBFF', '#f87be2', '#f2719a', '#fca4bb', '#f59a8f', '#fdb301', '#57e7ec', '#cf9ef1', '#5AD7D8', '#8163E9', '#FF5F45', '#B754F6', '#2998FF', '#938BF8'];
/**
 * -----------------------------------------------------------------------------------------------------------------------------------
 * 【分包】渲染echarts报表
 */
function showEchartsPage(dataList){
	var index = 0;
	for(var i=0; i<dataList.length; i++){
		if(index == colorList.length){
			index = 0;
		}
		dataList[i].itemStyle = {color: colorList[index]};
		index ++;
	}
	
	var option = {
	    title: [
	    {
	        text: '',
	        textStyle: {
	            fontSize: 14,
	            color:"#fff"
	        },
	        left: "50%"
	    },    
	    {
	        text: '分包',
	        subtext:  dataList.length+'个',
	        textStyle:{
	            fontSize: 18,
	            color:"#fff"
	        },
	        subtextStyle: {
	            fontSize: 20,
	            color: "#fff"
	        },
	        textAlign:"center",
	        x: '49%',
	        y: '40%',
	    }],
	    tooltip: {
	        trigger: 'item',
	        formatter:function (parms){
	          var str=  parms.seriesName+"</br>"+
	            parms.marker+""+parms.data.name+"</br>"+
	            "数量："+ parms.data.value+"</br>"+
	            "占比："+ parms.percent+"%";
	            return  str ;
	        }
	    },
	    series: [
	        {
	            name:'分包',
	            type:'pie',
	            center: ['50%', '52%'],
	            radius: ['55%', '85%'],
	            clockwise: true, //饼图的扇区是否是顺时针排布
	            avoidLabelOverlap: false,
	            label: {
                normal: {
                    show: false,
                }
            },
	            data: dataList
	        }
	    ]
	};
    myEcharts1.setOption(option);
}









